using System.Diagnostics.CodeAnalysis;
using MalwareMultiScan.Api.Extensions;
using MalwareMultiScan.Api.Services.Implementations;
using MalwareMultiScan.Api.Services.Interfaces;
using MalwareMultiScan.Backends.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace MalwareMultiScan.Api
{
    [ExcludeFromCodeCoverage]
    internal class Startup
    {
        private readonly IConfiguration _configuration;

        public Startup(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDockerForwardedHeadersOptions();

            services.Configure<KestrelServerOptions>(options =>
            {
                options.Limits.MaxRequestBodySize = _configuration.GetValue<int>("MaxFileSize");
            });

            services.AddMongoDb(_configuration);
            services.AddRabbitMq(_configuration);

            services.AddSingleton<IScanBackendService, ScanBackendService>();
            services.AddSingleton<IScanResultService, ScanResultService>();

            services.AddControllers();

            services.AddHostedService<ReceiverHostedService>();
        }

        public void Configure(IApplicationBuilder app)
        {
            app.UseRouting();
            app.UseForwardedHeaders();
            app.UseEndpoints(endpoints => endpoints.MapControllers());
        }
    }
}